package utils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.TimeZone;

public class NewDateUtils {

    public static void main(String[] args) {
        getCurrentDate();
        handleSpecialDate();
        System.out.println("LocalTime.now() = " + LocalTime.now());
        System.out.println("LocalDateTime.now() = " + LocalDateTime.now());
        System.out.println("getUTCTimeStr() = " + getUTCTimeStr());
    }

    /**
     * 返回的UTC时间戳
     * @return
     * @throws Exception
     */
    public static String getUTCTimeStr() {
        ZonedDateTime zdt = ZonedDateTime.now();
        System.out.println("zdt = " + zdt);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
        return formatter.format(zdt);
    }

    private static void getCurrentDate() {
        LocalDate today = LocalDate.now();
        System.out.println("today = " + today);

        int year = today.getYear();
        int month = today.getMonthValue();
        int day = today.getDayOfMonth();
        System.out.printf("Year : %d  Month : %d  day : %d t %n", year, month, day);
    }

    private static void handleSpecialDate() {
        LocalDate date = LocalDate.of(2020, 10, 20);
        System.out.println("date = " + date);
    }
}
